package com.ruoyi.buss.qmcy.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.csp.sentinel.util.StringUtil;
import com.ruoyi.buss.report.domain.ReportCkjgLsb;
import com.ruoyi.buss.report.domain.ReportXdywonlineLsb;
import com.ruoyi.buss.report.domain.ReportZhkhfxLsb;
import com.ruoyi.buss.report.service.IReportCkjgLsbService;
import com.ruoyi.buss.report.service.IReportZhkhfxLsbService;
import com.ruoyi.buss.utils.ListUtil;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.buss.qmcy.domain.QmcyCustCkjg;
import com.ruoyi.buss.qmcy.service.IQmcyCustCkjgService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 存款结构Controller
 * 
 * @author sxy
 * @date 2021-07-16
 */
@RestController
@RequestMapping("/reportLsb")
public class QmcyCustCkjgController extends BaseController
{
    @Autowired
    private IQmcyCustCkjgService qmcyCustCkjgService;

    @Autowired
    private IReportCkjgLsbService reportCkjgLsbService;

    @Autowired
    private IReportZhkhfxLsbService reportZhkhfxLsbService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询存款结构列表
     */
//    @PreAuthorize(hasPermi = "buss:ckjg:list")
//    @GetMapping("/ckjg")
//    public TableDataInfo ckjg(QmcyCustCkjg qmcyCustCkjg)
//    {
//        LoginUser userInfo = tokenService.getLoginUser();
//
//        if (qmcyCustCkjg.getTypeNum() != null && qmcyCustCkjg.getTypeNum() == 3) {
//
//        } else {
//            startPage("SJRQ ASC");
//        }
//        List<QmcyCustCkjg> list = qmcyCustCkjgService.selectQmcyCustCkjgList(qmcyCustCkjg, userInfo);
//        return getDataTable(list);
//    }

    /**
     * 查询存款结构列表
     */
    @PreAuthorize(hasPermi = "buss:ckjg:list")
    @GetMapping("/ckjg")
    public TableDataInfo ckjg(ReportCkjgLsb reportCkjgLsb)
    {
        reportCkjgLsb.setSjrq(ListUtil.getSjrq(reportCkjgLsb.getSjrq()));
        LoginUser userInfo = tokenService.getLoginUser();

        if (reportCkjgLsb.getTypeNum() != null && reportCkjgLsb.getTypeNum() == 3) {
            startPage("SJRQ ASC");
        } else {
            startPage("SJRQ DESC");
        }
        List<ReportCkjgLsb> list = reportCkjgLsbService.selectQmcyCustCkjgList(reportCkjgLsb, userInfo);
        return getDataTable(list);
    }

    /**
     * 导出查询存款结构列表
     */
    @PreAuthorize(hasPermi = "buss:dkjg:ckjgExport")
    @Log(title = "查询存款结构列表", businessType = BusinessType.EXPORT)
    @PostMapping("/ckjgExport")
    public void ckjgExport(HttpServletResponse response, ReportCkjgLsb reportCkjgLsb) throws IOException
    {
        reportCkjgLsb.setSjrq(ListUtil.getSjrq(reportCkjgLsb.getSjrq()));
        LoginUser userInfo = tokenService.getLoginUser();
        List<ReportCkjgLsb> list = reportCkjgLsbService.selectQmcyCustCkjgList(reportCkjgLsb, userInfo);
        ExcelUtil<ReportCkjgLsb> util = new ExcelUtil<ReportCkjgLsb>(ReportCkjgLsb.class);
        util.exportExcel(response, list, "查询存款结构列表");
    }
    /**
     * 支行客户趋势分析
     */
    @PreAuthorize(hasPermi = "buss:zhkhqsfx:list")
    @GetMapping("/zhkhqsfx")
    public TableDataInfo zhkhqsfx(ReportZhkhfxLsb reportZhkhfxLsb)
    {
        reportZhkhfxLsb.setSjrq(ListUtil.getSjrq(reportZhkhfxLsb.getSjrq()));
        LoginUser userInfo = tokenService.getLoginUser();

        if (reportZhkhfxLsb.getTypeNum() != null && reportZhkhfxLsb.getTypeNum() == 3) {
            startPage("SJRQ ASC");
        } else {
            startPage("SJRQ DESC");
        }
        List<ReportZhkhfxLsb> list = reportZhkhfxLsbService.zhkhqsfx(reportZhkhfxLsb, userInfo);
        return getDataTable(list);
    }

    /**
     * 导出支行客户趋势分析
     */
    @PreAuthorize(hasPermi = "buss:dkjg:zhkhqsfxExport")
    @Log(title = "支行客户趋势分析", businessType = BusinessType.EXPORT)
    @PostMapping("/zhkhqsfxExport")
    public void zhkhqsfxExport(HttpServletResponse response, ReportZhkhfxLsb reportZhkhfxLsb) throws IOException
    {
        reportZhkhfxLsb.setSjrq(ListUtil.getSjrq(reportZhkhfxLsb.getSjrq()));
        LoginUser userInfo = tokenService.getLoginUser();
        List<ReportZhkhfxLsb> list = reportZhkhfxLsbService.zhkhqsfx(reportZhkhfxLsb, userInfo);
        ExcelUtil<ReportZhkhfxLsb> util = new ExcelUtil<ReportZhkhfxLsb>(ReportZhkhfxLsb.class);
        util.exportExcel(response, list, "支行客户趋势分析");
    }
}
